<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="p" uri="/pagination-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="security" uri="/security-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>创建<s:property value="titleName"/>信息</title> 

 
</head>
<div id="breadcrumbs">
	<div style="overflow: hidden; position: relative; width: 750px;">
		<div>
			<ul style="width: 5000px;">
				<li class="first"></li>
				<li><a href="#">商品管理</a></li>
				<li><a href="#">产品信息管理</a></li>
				<li class="last"><a href="#">创建<s:property value="titleName"/></a></li>
			</ul>
		</div>
	</div>
</div>
<div class="section">
	<jsp:include page="/common/messages.jsp" />	
	
	<div class="box">
		<div class="title">
			入库单
			<span class="hide"></span>
		</div>
		<div class="content">
			<s:form namespace="/asn" method="get" 	id="searchRoleInRoleForm">
				<s:hidden name="asnHeader.id" id="thisroleid" />
				<table class="form_table">
				<tr>	
					<td ><label>入库单号 :</label></td><td><s:property value="asnHeader.seqNo"/></td>
					<td ><label>入库单类型 :</label></td><td> <s:property value="@com.smrs.asn.enums.AsnTypeEnum@toEnum(asnHeader.type).name" /></td>
					<td ><label>入库单状态 :</label></td><td> <s:property value="@com.smrs.asn.enums.AsnStatusEnum@toEnum(asnHeader.status).name" /></td>
				</tr>
				<tr>
					<td ><label>供应商名称 :</label></td><td> <s:property value="asnHeader.supplierName" /></td>
					<td ><label>供应商代码 :</label></td><td> <s:property value="asnHeader.supplierCode" /></td>
					<td ><label>产品数量 :</label></td><td> <s:property value="asnHeader.actualQuantify" /></td>					
				</tr>
				</table>
			</s:form>
		</div>
	</div>
	<!-- ---------------------------入库单包含的数据------------------------------------ -->
		
		<div style="margin: 10px">
			<div class="row">
				<s:form namespace="/hac" method="get" 	id="searchForm">
					<table class="form_table">
						<tr>
							<th><input type="button" value="添加Sku" class="button orange" id="addRoleBtn" onclick="addForm(<s:property value="asnHeader.id"/>)"/></th>
						</tr>
					</table>
				</s:form>
			</div>
			<div  id="roleInRoleListDiv" style="margin-top: 5px">
				<table id="roleInRoleList"></table> 
			    <div id="roleInRolePager"></div>   
			</div> 
		</div>
</div>


<script type="text/javascript">
function addForm(id ){
	document.getElementById('searchForm').onsubmit=function(){ return false; };
	window.location.href = "${dynamicURL}/asn/addSkuToAsnInit.action?asnHeader.id="+id;
}

function delAsnDetail(id ){
		//document.getElementById('searchForm').onsubmit=function(){ return false; };
		//window.location.href = "${dynamicURL}/asn/deleteAsnDetail.action?asnDetail.id="+id;
	if(!window.confirm("确定要从入库单中移除该产品Sku吗？")){
		return;
	}
	//var groupid = document.getElementById('thisgroupid').value; 
	var url = "${dynamicURL}/asn/deleteAsnDetail.action?asnDetail.id="+id;
	
	$.ajax({
		url: url,
		type: 'GET',
		success: function(data){
			$("#roleInRoleList").jqGrid().trigger('reloadGrid');
		},
		error: function(){
			hideOrShowRedAndGreen('red');
			addMessageInfo("red",'ajax移除人员过程出错！');
			return;
		}
	});
}
	
	
$(document).ready(function (){  
		//--------------------------------------角色包含角色-------------------------------------------------
		var roleInRoleGridList; 		
		var roleId = document.getElementById('thisroleid').value; 		
		roleInRoleGridList = {   
				url: 'searchAsnDetailJson.action?asnHeader.id='+roleId,
				colNames: ['id','商品编码', 'Sku编码', 'Sku名称', '价格', '数量','金额','操作'],
				colModel: [
					        {name:'id',index:'id', frozen:true, align:"left", hidden:true},
							{name:'itemCode',index:'itemCode', frozen:true, align:"left"},
					   		{name:'skuCode',index:'skuCode', align:"left"},
					   		{name:'skuName',index:'skuName', align:"left", width: '200'}, 
					   		{name:'actualPurchasePrice',index:'actualPurchasePrice', align:"center", width: '50',editable:true,editrules:{number:true}},
					   		{name:'actualQuantify',index:'actualQuantify', align:"center", width: '50',editable:true,editrules:{number:true}},
					   		{name:'actualAmount',index:'actualAmount', align:"center", width: '50'},
					   		{name:'btn',index:'btn',align:"center", width: '50'}
					   	], 
			   	shrinkToFit: false,
				height: 260,
				width: 700,
				rowNum: 10,
				forceFit:true,
				cellEdit:true,
				cellsubmit:'remote', 	
				cellurl:'updateAsnDetailJson.action',
				rownumbers: true,
				caption: '产品列表',
				pager: '#roleInRolePager',
				jsonReader:{
					root:"pager.records",
					total: "total",
					page: "page",
					records: "records",
					repeatitems: false,
					id:"0"},
				gridComplete: function() {
				        var grid = jQuery("#roleInRoleList");
				        var ids = grid.jqGrid('getDataIDs');	// 获取表格所有 行id
				        for (var i = 0; i < ids.length; i++) {
				            var rowId = ids[i];
				            var rowdata = grid.jqGrid('getRowData', rowId);
				            var tempBtn = "<img title='删除Sku' style='cursor:pointer' border='0'  src='${staticURL}/default/images/delete.png' onclick='delAsnDetail("+rowdata.id+")'>";  
				            grid.jqGrid('setRowData', rowId, { btn: tempBtn}); 
				        } 
				    },
				 afterSaveCell : function(rowid,name,val,iRow,iCol) { 
					   if(name == 'actualQuantify') { 
						   var price = jQuery("#roleInRoleList").jqGrid('getCell',rowid,iCol-1); 
						   var total = parseFloat(val)*parseFloat(price);
						   jQuery("#roleInRoleList").jqGrid('setRowData',rowid,{actualAmount:total}); 
						} 
					   if(name == 'actualPurchasePrice') { 
						   var quantify = jQuery("#roleInRoleList").jqGrid('getCell',rowid,iCol+1);
						   var total = parseFloat(val)*parseFloat(quantify);
						   jQuery("#roleInRoleList").jqGrid('setRowData',rowid,{actualAmount:total});
						}
					}    
		};
	
		$("#roleInRoleList").jqGrid(roleInRoleGridList);
		$("#roleInRoleList").setGridWidth(jQuery("#roleInRoleListDiv").width() * 0.98);
});

	
</script>


</html>
